home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / eflibpt4.zip / DEMO / MATH / MATHEULR.PAS < prev    next >
Pascal/Delphi Source File  |  1996-07-21  |  1KB  |  38 lines

  1. { Borland Pascal Extended Function Library - EFLIB (C) Johan Larsson, 1996
  2.   Demonstration; Euler's step method and Heun's method
  3.  
  4.   EFLIB IS PROTECTED BY THE COPYRIGHT LAW AND MAY NOT BE COPIED, SOLD OR
  5.   MANIPULATED. FOR MORE INFORMATION, SEE PROGRAM MANUAL! THIS DEMONSTRAT-
  6.   ION PROGRAM MAY FREELY BE USED AND DISTRIBUTED.                          }
  7.  
  8.  
  9. uses EFLIBMTH, EFLIBBAS, EFLIBTXT;
  10.  
  11.  
  12. const Iterations = 1000; { Number of iterations -
  13.                            larger value gives better precision in results }
  14.       Decimals   = 5;    { Number of decimals in evaluation }
  15.  
  16. var Expression : string; Result : real;
  17.  
  18. { Returns y'(x) there y is the function that should be solved }
  19. function Derivate (x, y : real) : real; far;
  20. begin
  21.      Derivate := EvaluateXYZ (Expression, X, Y, 0, Decimals);
  22. end;
  23.  
  24. begin
  25.      { Expression to solve }
  26.      Expression := 'x+y';
  27.  
  28.      { Euler's step method }
  29.      EulersStepMethod (0, 1, Iterations, 2, Result, @Derivate);
  30.      WriteLn ('Eulers step method: y''=x+y; y''(0)=2 => y(1)≈',Result:4:4,' with ', Iterations:0,' iterations.');
  31.  
  32.      WriteLn;
  33.      { Heun's method }
  34.      HeunsMethod (0, 1, Iterations, 2, Result, @Derivate);
  35.      WriteLn ('Heuns method: y''=x+y; y''(0)=2 => y(1)≈',Result:4:4,' with ', Iterations:0,' iterations.');
  36.  
  37.      WriteLn;
  38. end.